home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 22 / PCPP #22.iso / Quake2 / q2source_12_11 / utils3 / qe4 / win_cam.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-26  |  6.6 KB  |  252 lines

  1. // win_cam.c -- windows specific camera view code
  2.  
  3. #include "qe3.h"
  4.  
  5. /*
  6. ============
  7. CameraWndProc
  8. ============
  9. */
  10. LONG WINAPI WCam_WndProc (
  11.     HWND    hWnd,
  12.     UINT    uMsg,
  13.     WPARAM  wParam,
  14.     LPARAM  lParam)
  15. {
  16.     int        fwKeys, xPos, yPos;
  17.     RECT    rect;
  18.  
  19.     GetClientRect(hWnd, &rect);
  20.  
  21.     switch (uMsg)
  22.     {
  23.     case WM_CREATE:
  24.         {
  25.             HFONT    hfont;
  26.             
  27.             g_qeglobals.d_hdcBase = GetDC(hWnd);
  28.             QEW_SetupPixelFormat(g_qeglobals.d_hdcBase, true);
  29.  
  30.             if ( ( g_qeglobals.d_hglrcBase = wglCreateContext( g_qeglobals.d_hdcBase ) ) == 0 )
  31.                 Error ("wglCreateContext failed");
  32.             if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase ))
  33.                 Error ("wglMakeCurrent failed");
  34.  
  35.             Texture_SetMode(g_qeglobals.d_savedinfo.iTexMenu);
  36.  
  37.             //
  38.             // create GL font
  39.             //
  40.             hfont = CreateFont(
  41.                 10,    // logical height of font 
  42.                 7,    // logical average character width 
  43.                 0,    // angle of escapement 
  44.                 0,    // base-line orientation angle 
  45.                 0,    // font weight 
  46.                 0,    // italic attribute flag 
  47.                 0,    // underline attribute flag 
  48.                 0,    // strikeout attribute flag 
  49.                 0,    // character set identifier 
  50.                 0,    // output precision 
  51.                 0,    // clipping precision 
  52.                 0,    // output quality 
  53.                 0,    // pitch and family 
  54.                 0     // pointer to typeface name string 
  55.                 );
  56.  
  57.             if ( !hfont )
  58.                 Error( "couldn't create font" );
  59.  
  60.             SelectObject (g_qeglobals.d_hdcBase, hfont);
  61.  
  62.             if ( ( g_qeglobals.d_font_list = glGenLists (256) ) == 0 )
  63.                 Error( "couldn't create font dlists" );
  64.             
  65.             // create the bitmap display lists
  66.             // we're making images of glyphs 0 thru 255
  67.             if ( !wglUseFontBitmaps (g_qeglobals.d_hdcBase, 1, 255, g_qeglobals.d_font_list) )
  68.                 Error( "wglUseFontBitmaps faileD" );
  69.             
  70.             // indicate start of glyph display lists
  71.             glListBase (g_qeglobals.d_font_list);
  72.  
  73.             // report OpenGL information
  74.             Sys_Printf ("GL_VENDOR: %s\n", glGetString (GL_VENDOR));
  75.             Sys_Printf ("GL_RENDERER: %s\n", glGetString (GL_RENDERER));
  76.             Sys_Printf ("GL_VERSION: %s\n", glGetString (GL_VERSION));
  77.             Sys_Printf ("GL_EXTENSIONS: %s\n", glGetString (GL_EXTENSIONS));
  78.         }
  79.         return 0;
  80.     case WM_PAINT:
  81.         { 
  82.             PAINTSTRUCT    ps;
  83.             
  84.             if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase ))
  85.                 Error ("wglMakeCurrent failed");
  86.  
  87.             if ( BeginPaint(hWnd, &ps) )
  88.             {
  89.                 QE_CheckOpenGLForErrors();
  90.                 Cam_Draw ();
  91.                 QE_CheckOpenGLForErrors();
  92.  
  93.                 EndPaint(hWnd, &ps);
  94.                 SwapBuffers(g_qeglobals.d_hdcBase);
  95.             }
  96.         }
  97.         return 0;
  98.         
  99.     case WM_USER+267:    // benchmark
  100.         { 
  101.             PAINTSTRUCT    ps;
  102.             WINDOWPLACEMENT wp;
  103.             double    start, end;
  104.             int        i;
  105.             
  106.             memset( &wp, 0, sizeof( wp ) );
  107.             wp.length = sizeof( wp );
  108.             GetWindowPlacement( g_qeglobals.d_hwndCamera, &wp );
  109.             
  110.             MoveWindow( g_qeglobals.d_hwndCamera, 30, 30, 400, 400, TRUE );
  111.             
  112.             BeginPaint(hWnd, &ps);
  113.             if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase))
  114.                 Error ("wglMakeCurrent failed");
  115.             glDrawBuffer (GL_FRONT);
  116.             
  117.             start = Sys_DoubleTime ();
  118.             for (i=0 ; i<100 ; i++)
  119.             {
  120.                 camera.angles[YAW] = i*4;
  121.                 Cam_Draw ();
  122.             }
  123.             SwapBuffers(g_qeglobals.d_hdcBase);
  124.             glDrawBuffer (GL_BACK);
  125.             end = Sys_DoubleTime ();
  126.             EndPaint(hWnd, &ps);
  127.             Sys_Printf ("%5.2f seconds\n", end-start);
  128.  
  129.             SetWindowPlacement( g_qeglobals.d_hwndCamera, &wp );
  130.         }
  131.         break;
  132.         
  133.     case WM_KEYDOWN:
  134.         if ( QE_KeyDown (wParam) )
  135.             return 0;
  136.         else 
  137.             return DefWindowProc( hWnd, uMsg, wParam, lParam );
  138.         
  139.     case WM_MBUTTONDOWN:
  140.     case WM_RBUTTONDOWN:
  141.     case WM_LBUTTONDOWN:
  142.         if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
  143.             BringWindowToTop(hWnd);
  144.         
  145.         SetFocus (g_qeglobals.d_hwndCamera);
  146.         SetCapture (g_qeglobals.d_hwndCamera);
  147.         fwKeys = wParam;        // key flags 
  148.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  149.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  150.         yPos = (int)rect.bottom - 1 - yPos;
  151.         Cam_MouseDown (xPos, yPos, fwKeys);
  152.         return 0;
  153.         
  154.     case WM_MBUTTONUP:
  155.     case WM_RBUTTONUP:
  156.     case WM_LBUTTONUP:
  157.         fwKeys = wParam;        // key flags 
  158.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  159.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  160.         yPos = (int)rect.bottom - 1 - yPos;
  161.         Cam_MouseUp (xPos, yPos, fwKeys);
  162.         if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  163.             ReleaseCapture ();
  164.         return 0;
  165.         
  166.     case WM_MOUSEMOVE:
  167.         fwKeys = wParam;        // key flags 
  168.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  169.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  170.         yPos = (int)rect.bottom - 1 - yPos;
  171.         Cam_MouseMoved (xPos, yPos, fwKeys);
  172.         return 0;
  173.         
  174.     case WM_SIZE:
  175.         camera.width = rect.right;
  176.         camera.height = rect.bottom;
  177.         InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false);
  178.         return 0;
  179.  
  180.     case WM_KILLFOCUS:
  181.     case WM_SETFOCUS:
  182.         SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
  183.         return 0;
  184.  
  185.     case WM_NCCALCSIZE:// don't let windows copy pixels
  186.         DefWindowProc (hWnd, uMsg, wParam, lParam);
  187.         return WVR_REDRAW;
  188.  
  189.     case WM_CLOSE:
  190.         DestroyWindow (hWnd);
  191.         return 0;
  192.         
  193.     case WM_DESTROY:
  194.         QEW_StopGL( hWnd, g_qeglobals.d_hglrcBase, g_qeglobals.d_hdcBase );
  195.         return 0;
  196.     }
  197.  
  198.     return DefWindowProc( hWnd, uMsg, wParam, lParam );
  199. }
  200.  
  201.  
  202. /*
  203. ==============
  204. WCam_Create
  205. ==============
  206. */
  207. void WCam_Create (HINSTANCE hInstance)
  208. {
  209.     WNDCLASS   wc;
  210.     char        *title;
  211.  
  212.     /* Register the camera class */
  213.     memset (&wc, 0, sizeof(wc));
  214.  
  215.     wc.style         = 0;
  216.     wc.lpfnWndProc   = (WNDPROC)WCam_WndProc;
  217.     wc.cbClsExtra    = 0;
  218.     wc.cbWndExtra    = 0;
  219.     wc.hInstance     = hInstance;
  220.     wc.hIcon         = 0;
  221.     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
  222.     wc.hbrBackground = NULL;
  223.     wc.lpszMenuName  = 0;
  224.     wc.lpszClassName = CAMERA_WINDOW_CLASS;
  225.  
  226.     if (!RegisterClass (&wc) )
  227.         Error ("WCam_Register: failed");
  228.  
  229.     if (  g_qeglobals.d_savedinfo.exclude & EXCLUDE_DETAIL )
  230.         title = "Camera View (DETAIL EXCLUDED)";
  231.     else
  232.         title = "Camera View";
  233.  
  234.     g_qeglobals.d_hwndCamera = CreateWindow (CAMERA_WINDOW_CLASS ,
  235.         title,
  236.         QE3_STYLE,
  237.         ZWIN_WIDTH,
  238.         20,
  239.         (int)(screen_width*CWIN_SIZE),
  240.         (int)(screen_height*CWIN_SIZE),    // size
  241.  
  242.         g_qeglobals.d_hwndMain,    // parent window
  243.         0,        // no menu
  244.         hInstance,
  245.         0);
  246.     if (!g_qeglobals.d_hwndCamera)
  247.         Error ("Couldn't create g_qeglobals.d_hwndCamera");
  248.  
  249.     LoadWindowState(g_qeglobals.d_hwndCamera, "camerawindow");
  250.     ShowWindow (g_qeglobals.d_hwndCamera, SW_SHOWDEFAULT);
  251. }
  252.